package com.qf.flashlib.sharedpreferences;

import android.content.SharedPreferences;

import com.qf.flashlib.app.FlashLib;


/**
 * 不会随着账号退出而清空的SharePreferences
 * 2018/3/27 10:32
 */
public class SavePermanentSharePrefs
{
    /**
     * 新手引导版本号
     */
    public final static String PREFS_KEY_GUIDE_VERSION = "pref_key_guide_version";

    /* 持有私有静态实例，防止被引用，此处赋值为null，目的是实现延迟加载 */
    private static SavePermanentSharePrefs instance = null;

    /* 私有构造方法，防止被实例化 */
    private SavePermanentSharePrefs()
    {

    }

    /* 1:懒汉式，静态工程方法，创建实例 */
    public static SavePermanentSharePrefs getInstance()
    {
        if (instance == null)
        {
            instance = new SavePermanentSharePrefs();
        }
        return instance;
    }

    public String getDataString(String key)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getString(key, "");
    }

    public String getDataString(String key, String def)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getString(key, def);
    }

    public int getDataInt(String key)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getInt(key, 0);
    }

    public int getDataInt(String key, int value)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getInt(key, value);
    }

    public boolean getDataBoolean(String key, boolean defaltBol)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getBoolean(key, defaltBol);
    }

    public long getDataLong(String key)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        return settings.getLong(key, 0);
    }

    public void setData(String key, String value)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public void setData(String key, int value)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public void setData(String key, boolean value)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public void setData(String key, long value)
    {
        SharedPreferences settings = FlashLib.getInstance().getPreferencesSave();
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(key, value);
        editor.commit();
    }
}
